package com.example.multilevelapprovalback.listener;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.ReadConverterContext;
import com.alibaba.excel.converters.WriteConverterContext;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
public class LevelConverter implements Converter<Integer> {
    private static final String NATION = "国家级";
    private static final String PROVINCE = "省部级";
    private static final String BUREAU = "厅局级";
    private static final String SCHOOL = "校级";
    @Override
    public Class<?> supportJavaTypeKey() {
        return Converter.super.supportJavaTypeKey();
    }
    /**
     * 这里读的时候会调用
     * @param context
     * @return
     * @throws Exception
     */
    @Override
    public Integer convertToJavaData(ReadConverterContext<?> context) throws Exception {
        // 从context中读取数据
        String level = context.getReadCellData().getStringValue();
        if(NATION.equals(level)) {
            return 1;
        } else if(PROVINCE.equals(level)) {
            return 2;
        } else if (BUREAU.equals(level)) {
            return 3;
        } else if (SCHOOL.equals(level)) {
            return 4;
        } else {
            return 5;
        }
    }
    @Override
    public WriteCellData<?> convertToExcelData(WriteConverterContext<Integer> context) throws Exception {
        return Converter.super.convertToExcelData(context);
    }
}
